﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Xml.Linq;

namespace LastFmClient
{
    public sealed class TimerSingleton
    {
        TimerSingleton()
        {
            XmlDocs = new Dictionary<string, XElement>();
        }

        public static TimerSingleton Instance
        {
            get
            {
                return Nested.instance;
            }
        }

        class Nested
        {
            // Explicit static constructor to tell C# compiler
            // not to mark type as beforefieldinit
            static Nested()
            {
            }

            internal static readonly TimerSingleton instance = new TimerSingleton();
        }


        /// <summary>
        /// Holds the time when last fm was last accessed
        /// </summary>
        public DateTime LastAccessed { get; set; }

        /// <summary>
        /// If the interval between last accessed and now is greater than one second then it returns true.
        /// </summary>
        public bool IsAccessAllowed
        {
            get
            {
                if (LastAccessed == null)
                    return true;

                return (DateTime.Now - LastAccessed).TotalSeconds > 1;
            }
        }

        public Dictionary<string, XElement> XmlDocs { get; set; }

        
    }

}
